/**
 * qq邮箱
 * @Description 邮件发送
 * 调用方法:sendMail('123456789@qq.com','这是测试邮件', 'Hello World');
 * @Author blcyzycc
 * @Created 2018/05/09 15:10
 *
 */

const nodemailer = require('nodemailer');
const transporter = nodemailer.createTransport({
    //service: 'QQ', // 使用内置设置传输发送邮件，有bug，查看支持列表：https://nodemailer.com/smtp/well-known/
    host: 'smtp.qq.com',
    port: 465,
    secure: true, //两个都要设置
    secureConnection: true, //两个都要设置
    auth: {
        user: 'blcyz@qq.com',
        pass: 'hayxnwfohaboffce'
    }
});

/**
 * @param {String} recipient 收件人
 * @param {String} subject 发送的主题
 * @param {String} html 发送的html内容
 */

var sendMail = function (email, subject, html) {
    transporter.sendMail(
        {
            from: "Fred Foo <blcyz@qq.com>", // 发件地址
            to: email, // 收件邮箱
            subject: subject, // 标题
            html: html //html内容
        },
        (error, info) => {
            if (error) {
                return console.log(error);
            }
            console.log('Message sent: %s', info.messageId);
            // Preview only available when sending through an Ethereal account
            console.log('Preview URL: %s', nodemailer.getTestMessageUrl(info));
        }
    );
}
module.exports = sendMail;
